﻿@{
    ViewBag.Title = "流程监控";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
<script>
    $(function () {
        InitialPage();
        GetTree();
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 169.5);
                $("#itemTree").setTreeHeight($(window).height() - 52);
            }, 200);
            e.stopPropagation();
        });
    }
    //加载树
    function GetTree() {
        var item = {
            height: $(window).height() - 52,
            param: { EnCode: "FlowSort" },
            url: "../../FlowManage/FlowDesign/GetTreeJson",
            onnodeclick: function (item) {
                if (item.Sort != "SchemeType")
                {
                    var queryJson = { WFSchemeInfoId: item.id };
                    searchGrid(queryJson);
                }
            }
        };
        //初始化
        $("#itemTree").treeview(item);
    }
    //加载表格流程是否完成(0运行中,1运行结束,2被召回,3不同意,4表示被驳回)
    function GetGrid() {
        var selectedRowIndex = 0;
        $("#gridTable").jqGrid({
            url: "../../FlowManage/FlowProcess/GetProcessPageListJson",
            datatype: "json",
            height: $(window).height() - 169.5,
            autowidth: true,
            colModel: [
                { label: '主键', name: 'f_id', hidden: true },
                { label: '节点id', name: 'f_activityid', hidden: true },
                { label: '实例模板id', name: 'f_processschemeid', hidden: true },
                { label: '实例编号', name: 'f_code', index: 'f_code', width: 100, align: 'left' },
                { label: '实例名称', name: 'f_customname', index: 'f_customname', width: 150, align: 'left' },
                { label: '分类', name: 'f_schemetypename', index: 'f_schemetypename', width: 80, align: 'left' },
                {
                    label: "等级", name: "f_wflevel", index: "f_wflevel", width: 50, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == 1) {
                            return '<span  class=\"label label-danger\">重要</span>';
                        } else if (cellvalue == 2) {
                            return '<span  class=\"label label-primary\">普通</span>';
                        } else {
                            return '<span  class=\"label label-success\">一般</span>';
                        }
                    }
                },
                { label: "当前节点", name: "f_activityname", index: "f_activityname", width: 90, align: "left" },
                {
                    label: "状态", name: "f_isfinish", index: "f_isfinish", width: 80, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        if (rowObject.f_enabledmark == 1) {
                            if (cellvalue == 0) {
                                return '<span  class=\"label label-success\">运行中</span>';
                            }
                            else if (cellvalue == 1) {
                                return '<span  class=\"label label-info\">运行结束</span>';
                            }
                            else if (cellvalue == 2) {
                                return '<span  class=\"label label-important-learun\">取消</span>';
                            }
                            else if (cellvalue == 3) {
                                return '<span  class=\"label label-danger\">不同意</span>';
                            }
                            else if (cellvalue == 4) {
                                return '<span  class=\"label label-warning \">被驳回</span>';
                            }
                        }
                        else {
                            return '<span  class=\"label label-inverse-learun \">暂停</span>';
                        }

                        
                    }
                },
                { label: "创建用户", name: "f_createusername", index: "f_createusername", width: 80, align: "left" },
                {
                    label: "创建时间", name: "f_createdate", index: "f_createdate", width: 150, align: "left",
                    formatter: function (cellvalue, options, rowObject) {
                        return formatDate(cellvalue, 'yyyy-MM-dd hh:mm:ss');
                    }
                },
                { label: "备注", name: "f_description", index: "f_description", width: 200, align: "left" }
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'F_CreateDate desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = { Keyword: $("#txt_Keyword").val() };
            searchGrid(queryJson);
        });
    }
    //查询函数
    function searchGrid(queryJson) {
        $("#gridTable").jqGrid('setGridParam', {
            postData: { queryJson: JSON.stringify(queryJson) },
        }).trigger('reloadGrid');
    }
    //查看
    function btn_flowpreview()
    {
        var _processSchemeId = $("#gridTable").jqGridRowValue("f_processschemeid");
        var _processname = $("#gridTable").jqGridRowValue("f_customname");
        var _activityId = $("#gridTable").jqGridRowValue("f_activityid");
        if (_processSchemeId) {
            dialogOpen({
                id: "ProcessLookForm",
                title: '进度查看【' + _processname + '】',
                url: '../../FlowManage/FlowProcess/ProcessLookFrom?processSchemeId=' + _processSchemeId + '&activityId=' + _activityId,
                width: "1100px",
                height: "700px",
                btn: null,
                callBack: function (iframeId) {
                }
            });
        } else {
            dialogMsg('请选择需要查看的实例！', 0);
        }
    }
    //取消
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("f_id");
        if (keyValue) {
            $.ConfirmAjax({
                msg: "注：您确定要取消吗？该操作将无法恢复",
                url: "../../FlowManage/FlowProcess/OperateProcess",
                param: { keyValue: keyValue,state:2 },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择要取消的实例！', 0);
        }
    }
    //暂停
    function btn_disabled() {
        var keyValue = $("#gridTable").jqGridRowValue("f_id");
        if (keyValue) {
            $.ConfirmAjax({
                msg: "注：您确定要暂停吗？",
                url: "../../FlowManage/FlowProcess/OperateProcess",
                param: { keyValue: keyValue,state:0 },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择要暂停的实例！', 0);
        }
    }
    //启用
    function btn_enabled() {
        var keyValue = $("#gridTable").jqGridRowValue("f_id");
        if (keyValue) {
            $.ConfirmAjax({
                msg: "注：您确定要启用吗？",
                url: "../../FlowManage/FlowProcess/OperateProcess",
                param: { keyValue: keyValue ,state:1},
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择要启用的实例！', 0);
        }
    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel">
            <div class="panel-Title">流程模板</div>
            <div id="itemTree"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="panel-Title">流程实例</div>
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td>
                                <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-flowpreview" class="btn btn-default" onclick="btn_flowpreview()"><i class="fa fa-eye"></i>&nbsp;查看</a>
                    </div>
                    <div class="btn-group">
                        <a id="lr-disabled" class="btn btn-default" onclick="btn_disabled()"><i class="fa fa-stop"></i>&nbsp;暂停</a>
                        <a id="lr-enabled" class="btn btn-default" onclick="btn_enabled()"><i class="fa fa-play"></i>&nbsp;启用</a>
                        <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;取消</a>
                    </div>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>

